{/* LAYOUT模板 */}
	<layout name="layout"/>
{/* LAYOUT模板 */}

{/* import Js,Css */}
	<js href="__PUBLIC__/js/admin/listTable.js"/>
	<js href="__PUBLIC__/js/admin/js.util.js"/>
	<css href="__PUBLIC__/css/admin/common.css"/>
	<js href="__PUBLIC__/js/admin/js.selectzone.js"/>
	
	<css href="__PUBLIC__/css/jquery-ui.css" />
	<js href="__PUBLIC__/js/core/jquery-ui.1.10.4.js" />
	<js href="__PUBLIC__/js/core/plugins.js"/>
{/* import js,css */}

<!-- [position] -->
	<include file="Template:position"/>
<!-- [position] -->
<!-- [position] -->
	<include file="Core:QTip"/>
<!-- [position] -->



<form id="nodeForm" method="post" action="__URL__/mod_role_ok">
	<table>
		<tr>	
			<td>用户组名称</td>
			<td><input type="text" class="input" name="name" value="{$role.name}"/></td>
		</tr>
		<tr>	
			<td>父id</td>
			<td><input type="text" class="input" name="pid"  readonly="true" value="{$role.pid}"/></td>
		</tr>
		<tr>	
			<td>启用用户组</td>
			<td>
				<input type="checkbox" name="status" value="1"/>是
				<input type="checkbox" name="status" value="0"/>否
			</td>
		</tr>
		<tr>	
			<td>备注</td>
			<td><input type="text" class="input" name="remark" value="{$role.remark}"/></td>
		</tr>			
	</table>
	
	<!-- [权限列表] -->
	<table>
		<volist name="controllerList" id="controller">
			<tr>
				<td>
					{$controller.blank}
					<input type="checkbox" 
						
						   <if condition="$controller.role_id neq null">
						   		values="{$controller.level}_{$controller.name}"
						   </if>	
					
						   datas="{$controller.id}_{$controller.name}-{$controller.pid}_{$controller.p_name}" 
						   onclick="check('{$controller.id}_{$controller.name}','{$controller.pid}_{$controller.p_name}',{$controller.level},this);" 
						   name="chkGroup[]" 
						   value="{$controller.id}-{$controller.level}-{$controller.pid}-{$controller.name}"/>
					{$controller.title}
				</td>		
			</tr>	
		</volist>		
	</table>
	<!-- [权限列表] -->
	<label>
		<input type="checkbox" name="checkall" value="checkbox" onclick="checkAll(this.form, this);" class="checkbox" />
		全选
	</label>
		
	<input type="hidden" name="id" value="{$role.id}"/>
	<input type="submit" value="提交修改"/>
</form>

<script>
	//初始化radio,checkbox
	function initInput(name,value){
		if(typeof name== 'undefined') return ;
		if(typeof value== 'undefined') return ;
		var inputObj   =   document.getElementsByName(name);
		
		for(var i = 0; inputObj.length; i ++ ){
			//alert(inputObj[i].value + " : " + value);
			if(inputObj[i].value == value){
				inputObj[i].checked = true;
				break;
			}
		}	
	}	
	//初始化input
	initInput('status',{$role.status});
	
	/**
	 * 初始化权限
	 * @param	node_id int
	 * @param 	name 	string
	 *
	 */
	function initAccess(){
		var nodeForm	=	document.getElementById('nodeForm');
	  	var inputList	=	nodeForm.getElementsByTagName('input');		
		
		for(var i = 0 ; i < inputList.length; i ++){
	  		if(inputList[i].name == 'action[]' || inputList[i].name == 'chkGroup[]'){
	  			//alert(inputList[i].getAttribute('datas'));
	  			//console.log(inputList[i].getAttribute('values'));
	  			if(inputList[i].getAttribute('values') != null){
	  				inputList[i].checked = true;
	  			}
	  		}
	  	}
	}
	initAccess();
	

	//select all
	function checkAll(frm, checkbox)
	{
	  	for (i = 0; i < frm.elements.length; i++)
	 	{
			if (frm.elements[i].name == 'action[]' || frm.elements[i].name == 'chkGroup[]')
			{
		 	 frm.elements[i].checked = checkbox.checked;
			}
	 	}
	}	
	//select the controller
	function check(str1, str2,level,checkbox)
	{
		var nodeForm	=	document.getElementById('nodeForm');
	  	var inputList	=	nodeForm.getElementsByTagName('input');
		
	  	console.log('查找字符串: ' + str1);
		
		
		switch(level){
			case 1:
				//首先找出与自己想通的二级控制器
				for(var i = 0 ; i < inputList.length; i ++){
			  		//console.log(inputList[i].getAttribute('datas'));
			  		if(inputList[i].name == 'action[]' || inputList[i].name == 'chkGroup[]'){
			  			//查找有没有存在该字符串
			  			var string	=	inputList[i].getAttribute('datas');
			  			if(string.indexOf(str1) > 0){
			  				console.log(inputList[i].getAttribute('datas'));
			  				inputList[i].checked	=	checkbox.checked;
			  				var stringArray			=	string.split('-');
			  				
			  				//console.log(stringArray[0]);
			  				for(var j = 0; j < inputList.length; j ++){
			  					if(inputList[j].name == 'action[]' || inputList[j].name == 'chkGroup[]'){
			  						var _string		=	inputList[j].getAttribute('datas')
			  						if(_string.indexOf(stringArray[0]) > 0){
			  							inputList[j].checked	=	checkbox.checked;
			  						}
			  					}
			  				}
			  			}		  			
			  		}
			  	}
				
			break;
			case 2:
				for(var i = 0 ; i < inputList.length; i ++){
			  		if(inputList[i].name == 'action[]' || inputList[i].name == 'chkGroup[]'){
			  			//alert(inputList[i].getAttribute('datas'));
			  			//console.log(inputList[i].getAttribute('datas'));
			  			var string 	=	inputList[i].getAttribute('datas');
			  			if(string.indexOf(str1) >  0){
			  				inputList[i].checked	=	checkbox.checked;
			  			}
			  		}
			  	}
			break;
			default:break;
		}
		
	}
	
</script>



<include file="Template:pagefooter"/>